import { BaseAvatar } from "./BaseAvatar";
import { EntityInfo } from "../../scene/player/info/EntityInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { EEntityFightMode } from "../../../../Message/Public/EEntityFightMode";
import { AvatarNameBg } from "./AvatarNameBg";
import { AttachType } from "../../scene/player/type/AttachType";
import { EntityType } from "../../rules/EntityType";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { SEntityInfo } from "../../../../Message/BroadCast/SEntityInfo";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { PetOpRegister } from "../common/menu/PetOpRegister";
import { PetOpMenuConst } from "../common/menu/PetOpMenuConst";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { PetInfo } from "../../resource/info/PetInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { BossConfig } from "../../resource/BossConfig";
type int = number;
//class AimAvatar
    
    export  class AimAvatar extends BaseAvatar
    {
        constructor(arg1: EntityInfo)
        {
            super(this._aimEntityInfo.entityInfo);
            this._aimEntityInfo = arg1;
            this._attachType = this._aimEntityInfo.attachType;
            Dispatcher.addEventListener(EventName.PlayerAvatarUpdate, this.onPlayerAvatarUpdate);
            return;
        }

        /* internal  */onPlayerAvatarUpdate(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data as SEntityId;
            if (EntityUtil.equal(this._aimEntityInfo.entityInfo.entityId, loc1)) 
            {
                loc2 = entityInfo;
                this.updateAvatar(loc2);
            }
            return;
        }

        public /* override */ init(): void
        {
            this.isShowHealthLabelTip = false;
            this.isShowManaLabelTip = false;
            super.init();
            createEffects(5, 87, 42);
            this.addCampBitmap();
            this.updateAimAvatarUI(this._aimEntityInfo);
            this.resetAvatar();
            return;
        }

        /* internal  */createModeBtn(): void
        {
            this._modeBtn = new GButton();
            this._modeBtn.label = "";
            this._modeBtn.setSize(27, 27);
            this._modeBtn.x = 60;
            this._modeBtn.y = 50;
            this._modeBtn.visible = false;
            this.addChild(this._modeBtn);
            return;
        }

        /* internal  */addCampBitmap(): void
        {
            this._campBitmap = GlobalClass.getBitmap(ImagesConst.CampXiao);
            this._campBitmap.width = 25;
            this._campBitmap.height = 26;
            this._campBitmap.x = -10;
            this._campBitmap.y = 10;
            this.addChild(this._campBitmap);
            return;
        }

        /* internal  */updateModeButton(arg1: int): void
        {
            if (arg1 != EEntityFightMode._EEntityFightModePeace) 
            {
                this._modeBtn.styleName = "FightModeButton";
            }
            else 
            {
                this._modeBtn.styleName = "PeaceModeButton";
            }
            return;
        }

        public resetAvatar(): void
        {
            mainBgName = ImagesConst.AimAvatarBg_green;
            this.updateAvatar(entityInfo);
            this.healthBar.setSize(95, 8);
            healthBar.progressBarClass = ImagesConst.Shengmingtiao;
            magicBar.setSize(95, 8);
            magicBar.progressBarClass = ImagesConst.Mofatiao;
            this.resetPosition();
            return;
        }

        public /* override */ createAvatar(): void
        {
            avatarBitmap = new Object /* flash.display.Bitmap */();
            avatarBitmap.x = 11;
            avatarBitmap.y = 8;
            this._operMenuSprite = new Object /* flash.display.Sprite */();
            this._operMenuSprite.buttonMode = true;
            this._operMenuSprite.x = 14;
            this._operMenuSprite.y = 8;
            this._operMenuSprite.graphics.beginFill(16711680, 0);
            this._operMenuSprite.graphics.drawRect(0, 0, 47, 47);
            this._operMenuSprite.cacheAsBitmap = true;
            this.addChild(avatarBitmap);
            this.addChild(this._operMenuSprite);
            this._operMenuSprite.addEventListener(flash.events.MouseEvent.CLICK, this.onOperMenuSpriteClickHandler);
            return;
        }

        /* internal  */createNameBg(): void
        {
            this._nameBg = GlobalClass.getBitmap(AvatarNameBg.Default);
            this._nameBg.width = 90;
            this._nameBg.x = 70;
            this._nameBg.y = 0;
            this.addChild(this._nameBg);
            return;
        }

        /* internal  */updateNameBg(): void
        {
            this._attachType = this._aimEntityInfo.attachType;
            var loc1="";
            if (this._attachType != AttachType.AttackSelf) 
            {
                if (this._attachType == AttachType.HasAttackNoSelf || this._attachType == AttachType.AttackTeamMate) 
                {
                    loc1 = AvatarNameBg.Gray;
                }
                else if (this._attachType != AttachType.NoAttack) 
                {
                    loc1 = AvatarNameBg.Default;
                }
                else 
                {
                    loc1 = AvatarNameBg.Default;
                }
            }
            else 
            {
                loc1 = AvatarNameBg.Red;
            }
            if (loc1 != this._nameBgName) 
            {
                this._nameBg.bitmapData = GlobalClass.getBitmapData(loc1);
                this._nameBgName = loc1;
            }
            return;
        }

        public updateAimAvatarUI(arg1: EntityInfo): void
        {
            this._aimEntityInfo = arg1;
            this.entityInfo = arg1.entityInfo;
            var loc1=arg1.entityInfo;
            this.updateAvatar(loc1);
            super.updateAvatarUI(loc1);
            this.updateOperMenu(loc1);
            if (loc1 && loc1.entityId) 
            {
                if (loc1.entityId.type != EntityType.Player) 
                {
                    this._campBitmap.bitmapData = null;
                }
                else 
                {
                    this._campBitmap.bitmapData = GlobalClass.getBitmapData(AvatarInfo.getPicNameByCamp(this.entityInfo.camp));
                }
            }
            mainBgName = this.getAvatarBgName(arg1);
            return;
        }

        /* internal  */updateOperMenu(arg1: SEntityInfo): void
        {
            if (arg1 && arg1.entityId) 
            {
                if (arg1.entityId.type != EntityType.Player) 
                {
                    if (arg1.entityId.type != EntityType.Pet) 
                    {
                        PlayerOpRegister.UnRegister(this._operMenuSprite);
                        PetOpRegister.UnRegister(this._operMenuSprite);
                        this._operMenuSprite.buttonMode = false;
                    }
                    else 
                    {
                        PetOpRegister.UnRegister(this._operMenuSprite);
                        PlayerOpRegister.UnRegister(this._operMenuSprite);
                        PetOpRegister.Register(this._operMenuSprite, arg1, PetOpMenuConst.AimAvatarOpMenu);
                        this._operMenuSprite.buttonMode = true;
                    }
                }
                else 
                {
                    PlayerOpRegister.UnRegister(this._operMenuSprite);
                    PetOpRegister.UnRegister(this._operMenuSprite);
                    if (this._sMiniPlayer == null) 
                    {
                        this._sMiniPlayer = new SPublicMiniPlayer();
                    }
                    this._sMiniPlayer.camp = arg1.camp;
                    this._sMiniPlayer.career = arg1.career;
                    this._sMiniPlayer.careerEnable = arg1.careerEnable;
                    this._sMiniPlayer.entityId = arg1.entityId;
                    this._sMiniPlayer.level = arg1.level;
                    this._sMiniPlayer.name = arg1.name;
                    this._sMiniPlayer.online = 1;
                    this._sMiniPlayer.sex = arg1.sex;
                    if (this._playerMiniInfo == null) 
                    {
                        this._playerMiniInfo = new PlayerMiniInfo();
                    }
                    this._playerMiniInfo.miniPlayer = this._sMiniPlayer;
                    PlayerOpRegister.Register(this._operMenuSprite, this._playerMiniInfo);
                    this._operMenuSprite.buttonMode = true;
                }
            }
            return;
        }

        public updateAvatar(arg1: SEntityInfo): void
        {
            var loc1=this._avatarName;
            if (arg1 && arg1.entityId) 
            {
                if (arg1.entityId.type != EntityType.Player) 
                {
                    if (arg1.entityId.type == EntityType.Boss || arg1.entityId.type == EntityType.Transport) 
                    {
                        loc1 = AvatarInfo.getBossAvatarName(arg1.code);
                        healthBar.showPercentText = true;
                        magicBar.showPercentText = true;
                    }
                    else if (arg1.entityId.type == EntityType.Pet) 
                    {
                        loc1 = PetInfo.getPetAvatarName(arg1.code);
                        healthBar.showPercentText = false;
                        magicBar.showPercentText = false;
                    }
                }
                else 
                {
                    loc1 = AvatarInfo.getPlayerAvatarName(arg1.camp, arg1.sex, AvatarType.SMALL, arg1.avatarId);
                    healthBar.showPercentText = false;
                    magicBar.showPercentText = false;
                }
                avatarName = loc1;
            }
            return;
        }

        /* internal  */getAvatarBgName(arg1: EntityInfo): string
        {
            var loc2=null;
            var loc1=ImagesConst.AimAvatarBg_green;
            if (arg1 && arg1.entityInfo && arg1.entityInfo.entityId) 
            {
                if (arg1.entityInfo.entityId.type == EntityType.Boss) 
                {
                    loc2 = BossConfig.instance.getInfoByName(arg1.entityInfo.code);
                    if (!loc2) 
                    {
                    };
                }
            }
            return loc1;
        }

        /* internal  */onOperMenuSpriteClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (entityInfo.entityId.type == EntityType.Pet) 
            {
                PetOpRegister.UnRegister(this._operMenuSprite);
                PetOpRegister.Register(this._operMenuSprite, entityInfo, PetOpMenuConst.AimAvatarOpMenu);
            }
            return;
        }

        public resetPosition(): void
        {
            avatarBitmap.x = 9;
            avatarBitmap.y = 5;
            levelLabel.x = 17;
            levelLabel.y = 40;
            nameLabel.x = 65;
            nameLabel.y = 0;
            healthBar.move(68, 20);
            magicBar.move(68, 29);
            return;
        }

        /* internal */ /* var */_operMenuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_modeBtn: GButton;

        /* internal */ /* var */_campBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_avatarName: string="";

        /* internal */ /* var */_sMiniPlayer: SPublicMiniPlayer;

        /* internal */ /* var */_backupEntity: SEntityInfo;

        /* internal */ /* var */_aimEntityInfo: EntityInfo;

        /* internal */ /* var */_nameBgName: string="";

        /* internal */ /* var */_attachType: int;

        /* internal */ /* var */_playerMiniInfo: PlayerMiniInfo;
    }
